package com.weiyi.portal.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.weiyi.common.common.api.CommonPage;
import com.weiyi.common.common.api.CommonResult;
import com.weiyi.portal.dto.PmsProductDTO;
import com.weiyi.portal.dto.PmsProductDetailDTO;

import com.weiyi.portal.modules.pms.service.PmsProductAttributeCategoryService;
import com.weiyi.portal.modules.pms.service.PmsProductAttributeService;
import com.weiyi.portal.modules.pms.service.PmsProductCategoryService;
import com.weiyi.portal.modules.pms.service.PmsProductService;
import com.weiyi.portal.modules.ums.model.UmsNews;
import com.weiyi.portal.modules.ums.service.UmsNewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/design")
public class DesignController {

    @Autowired
    PmsProductAttributeService pmsProductAttributeService;
    @Autowired
    PmsProductCategoryService pmsProductCategoryService;
    @Autowired
    PmsProductAttributeCategoryService pmsProductAttributeCategoryService;
    @Autowired
    PmsProductService pmsProductService;
    @Autowired
    UmsNewsService umsNewsService;

    /**
     * 获取衣服属性及其分类
     * @param id 衣服种类id
     * @return
     */
    @RequestMapping(value = "/getAttribute/{id}", method = RequestMethod.GET)
    public CommonResult getDetail(@PathVariable Long id){
        List<PmsProductDetailDTO> detail = pmsProductAttributeService.getDetail(id);
        return CommonResult.success(detail);
    }

    /**
     * 分页获取全部衣服类型
     * @param pageNum
     * @param pageSize
     * @return
     */
    @RequestMapping(value = "/getAllCategory", method = RequestMethod.GET)
    public CommonResult<CommonPage> getAllCategory(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                   @RequestParam(value = "pageSize", defaultValue = "4") Integer pageSize){
        Page page = pmsProductCategoryService.getAllCategory(pageNum, pageSize);
        return CommonResult.success(CommonPage.restPage(page));
    }

    /**
     * 保存商品
     * @param product
     * @return
     */
    @RequestMapping(value = "/saveProduct", method = RequestMethod.POST)
    public CommonResult saveProduct(@RequestBody PmsProductDTO product){
        Boolean flag = pmsProductService.create(product);
        if(flag)return CommonResult.success(flag);
        return CommonResult.failed();
    }
}
